import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import CategoryView from '../views/CategoryView.vue'
import ProductView from '../views/ProductView.vue'
import CartView from '../views/CartView.vue'
import HelpCenterView from '../views/HelpCenterView.vue'
import LoginView from '../views/LoginView.vue'
import MyOrdersView from '../views/MyOrdersView.vue'
import QuickOrderView from '../views/QuickOrderView.vue'
import ProfileView from '@/views/profile/ProfileView.vue'
import BasicInfo from '@/views/profile/BasicInfo.vue'
import PasswordChange from '@/views/profile/PasswordChange.vue'
import Footprints from '@/views/profile/Footprints.vue'
import Favorites from '@/views/profile/Favorites.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: HomeView
    },
    {
      path: '/category/:id',
      name: 'category',
      component: CategoryView,
      props: true
    },
    {
      path: '/product/:id',
      name: 'product',
      component: ProductView,
      props: true
    },
    {
      path: '/products',
      name: 'products',
      component: () => import('@/views/ProductsView.vue')
    },
    {
      path: '/next-products',
      name: 'next-products',
      component: () => import('@/views/ProductsView.vue')
    },
    {
      path: '/quick-order',
      name: 'quick-order',
      component: QuickOrderView
    },
    {
      path: '/cart',
      name: 'cart',
      component: CartView
    },
    {
      path: '/help-center',
      name: 'help-center',
      component: HelpCenterView
    },
    {
      path: '/login',
      name: 'login',
      component: LoginView
    },
    {
      path: '/my-orders',
      name: 'my-orders',
      component: MyOrdersView
    },
    // Promotion routes
    {
      path: '/promotions/combo',
      name: 'combo-promotion',
      component: () => import('@/views/promotions/ComboPromotionView.vue'),
      meta: { title: '套餐促销' }
    },
    {
      path: '/promotions/seckill',
      name: 'seckill-promotion',
      component: () => import('@/views/promotions/SeckillPromotionView.vue'),
      meta: { title: '限时秒杀' }
    },
    {
      path: '/promotions/full-reduction',
      name: 'full-reduction-promotion',
      component: () => import('@/views/promotions/FullReductionView.vue'),
      meta: { title: '满减优惠' }
    },
    {
      path: '/promotions/buy-gift',
      name: 'buy-gift-promotion',
      component: () => import('@/views/promotions/BuyGiftView.vue'),
      meta: { title: '买赠活动' }
    },
    {
      path: '/profile',
      component: ProfileView,
      redirect: '/profile/basic',
      children: [
        {
          path: 'basic',
          name: 'profile-basic',
          component: BasicInfo,
          meta: { title: '基础信息' }
        },
        {
          path: 'password',
          name: 'profile-password',
          component: PasswordChange,
          meta: { title: '修改密码' }
        },
        {
          path: 'footprints',
          name: 'profile-footprints',
          component: Footprints,
          meta: { title: '我的足迹' }
        },
        {
          path: 'favorites',
          name: 'profile-favorites',
          component: Favorites,
          meta: { title: '我的收藏' }
        }
      ]
    }
  ],
  scrollBehavior(savedPosition: any) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0 }
    }
  }
})

export default router 